package com.panel;

import com.util.GameUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author: Combo
 * @time: 2020/12/30 13:34
 * @description: 绘制窗口类
 */
public class MyPanel extends JPanel {
    public String path;         // 图片地址
    public Image background;    // 背景图片
    public int x;               // x 窗口坐标
    public int y;               // y 窗口坐标
    public int width;           // 窗口宽
    public int height;          // 窗口高

    /**
     * 使用构造函数对变量进行赋值
     * @param path
     * @param x
     * @param y
     * @param width
     * @param height
     */
    public MyPanel(String path, int x, int y, int width, int height) {
        this.path = path;
        this.background = GameUtil.getImage(path);
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    /**
     * 窗口绘制
     * @param g
     */
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(background, x, y, width, height, null);
    }
}
